/**************************************************************/
/*这个程序的主要作用就是不断读取由FPGA传过来的数据并显示*/
#include <stdio.h>  
#include <sys/io.h> 
#include <unistd.h>
#define setbit(x,y) x|=(1<<y)
#define clrbit(x,y) x&=~(1<<y)
int main(unsigned char data)
{
unsigned char x;
int BASE=0x378;
int statusport = BASE + 1;
int controlport = BASE + 2;
unsigned char status,control;
unsigned char ctl;
//char x;
iopl(3);
ioperm(BASE,0x4ff,1);          
unsigned char EPP_ECR = 0x80;
unsigned char old_ECR = inb_p(BASE + 0x402); /* Paused IO for example */
unsigned char low_bits = old_ECR & 0x1f; /* save 5 lowest bits */ 
unsigned char new_ECR = EPP_ECR | low_bits;
outb_p(new_ECR, BASE + 0x402); /* set the port to EPP */

ctl = inb(controlport);
ctl = (ctl &= 0xF0) | 0x4;
outb(ctl, controlport);
//下面这句非常重要，controlport的bit5设置为1否则不能正确通信
ctl= inb(controlport);
setbit(ctl,5);
outb(ctl,controlport);


if ((inb(statusport) & 0x01)) {//if the bit0 ==1,means TIME OUT
  status = inb(statusport); 
  outb(status | 0x01, statusport); /* Some reset by writing 1 */ 
  outb(status & 0xfe, statusport); /* Others by writing 0 */
}

do{
	//control=inb(controlport);
	//outb(control|20, controlport);
	x=inb(BASE+4);
	printf("%x ",x);
	if ((inb(statusport) & 0x01)) {//if the bit0 ==1,means TIME OUT
	printf("!");
	status = inb(statusport);
	outb(status | 0x01, statusport); //Some reset by writing 1 
	outb(status & 0xfe, statusport); //Others by writing 0 
	}
	
}while(1/*(x==0xc3)||(x==0xf0)*/);

printf("nonono");

ioperm(BASE,0x4ff,0);  
return 0;
}  
